﻿using COC.Commons;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace COC.Tool
{
    

    public partial class AddCommentView : Form
    {
        private readonly CodingPlan _CodingPlan = new CodingPlan();
        private PlanTask _PlanTask;

        public AddCommentView(PlanTask pt)
        {
            InitializeComponent();
            this._PlanTask = pt;
            this.IDText.Text = pt.Id;
            this.TypeText.Text = pt.Type;
            this.StateText.Text = pt.State;
            this.ContentText.Text = pt.Content;
        }

        private void AddCommentYes_Click(object sender, EventArgs e)
        {
            //这里应该做两件事，第一件事在备注集合中增加备注，第二件事把增加的备注写入到文件中。
            if (string.IsNullOrEmpty(CommentText.Text))
            {
                MessageBox.Show(@"备注内容为空，保存失败。");
                this.Close();
                return;
            }
            var tc = new TaskComment();
            tc.Id = (_PlanTask.Comments.Count + 1).ToString();
            tc.Time = DateTime.Now.ToString("yyyy/MM/dd");
            tc.Content = CommentText.Text;
            _PlanTask.Comments.Add(tc);
            _CodingPlan.SaveNewComment(_PlanTask.Id,tc);
            
            this.Close();
        }

        private void AddCommentNo_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
